package com.milk_shop.dao.imp;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;

import com.milk_shop.dao.UserDao;
import com.milk_shop.model.User;

@Component
public class UserDaoImp extends BaseDao<User> implements UserDao {
	@Resource
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public User getUserByPhone(String phone) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from user where phone=:phone").setParameter("phone",phone);
		return getModel(query);
	}

	@Override
	protected Class<User> getType() {
		return User.class;
	}
}
